package JUnit4;

class NumberOutOfBoundsException extends Exception {

	private static final long serialVersionUID = 634689564236168634L;
	
}

class WrongBaseException extends Exception {

	private static final long serialVersionUID = -8977728907619994327L;
	
}

public class Liczba {
	
	private int liczba;

	public Liczba(int liczba) throws NumberOutOfBoundsException {
		if (liczba < 0) {
			throw new NumberOutOfBoundsException();
		} else {
			this.liczba = liczba;
		}
	}
	
	public void setLiczba(int liczba) throws NumberOutOfBoundsException {
		if (liczba < 0) {
			throw new NumberOutOfBoundsException();
		} else {
			this.liczba = liczba;
		}
	}
	
	public String getNumberInBase(int base) throws WrongBaseException {
		if (!(base >= 2 && base <= 16)) {
			throw new WrongBaseException();
		} else if (this.liczba == 0) {
			return "0"; 
		}
		else {
			String convertedNumber = "";
			int number = this.liczba;
			
			while (number != 0) {
				convertedNumber = this.divideModuloIntByInt(number, base) + convertedNumber;
				number = number / base;
			}
			
			return convertedNumber;
		}
	}
	
	private String divideModuloIntByInt(int numberA, int numberB) {
		int result = numberA % numberB;
		if (result < 10) {
			return "" + result;
		} else {
			return this.getLetterForNumber(result);
		}
	}
	
	private String getLetterForNumber(int number) {
		switch (number) {
		case 10: return "A";
		case 11: return "B";
		case 12: return "C";
		case 13: return "D";
		case 14: return "E";
		case 15: return "F";
		default: return "";
		}
	}

}